

** Code for replication
** Article title: Do anti-poverty policies sway voters? Evidence from a meta-analysis of Conditional Cash Transfers
** Author: Victor Araújo (University of Zurich)
** This version: January 2021
** ALL the commands below were executed using a licensed version of the STATA 16


** Getting the data (please update the path below according to your local directory)
clear
use "G:\My Drive...data_meta_rap.dta"


** PAY ATTENTION!
** Since I already implemented (and save in the dataset) lines 19 to 25, one can skip those lines and goes directly to the commands that implement the meta-analysis. 
**** calculating the T statistics
gen t_stat = effect/sd_effect
** calculating the partical correlation 
**** ATTENTION!! The commands used to calculate each estimate's partial correlation creates a positive value by construction. Therefore, one must convert (by hand) this value into a negative one if the t-statistic carried that sign. Thus, bounding the value of calculated partial correlations between -1 and 1.
gen part_corr = t^2/(t^2+ n_cases-2)
replace part_corr = sqrt(part_corr)
**calculating the partial correlation of standard error
gen part_se = sqrt((1-part_corr)/(n_cases-2))


**Setting the method for running meta-analysis (CI of 95%)
*In this paper, I use random-effect models (REM) - REM is the default option in STATA
meta set part_corr part_se, studylabel(short_name) eslabel(Partial Correlation) level(95)

**Describing key variables for meta-analysis
describe _meta*
 
***************************************************************************************************
****************** ANALYSIS **************************
***************************************************************************************************

**************************************
*Setting the graphical scheme to generate nice plots

ssc install blindschemes, replace all
set scheme plotplain

**************************************

*** Ploting the overall size effect using effects of all estimates (reported in the main text)
meta update, random
meta summarize
meta forestplot, esrefline

** Main results of meta-analysis using common effects (reported in the appendix)
meta update, common
meta summarize
meta forestplot, esrefline


** Main results of meta-analysis using fixed effects (reported in the appendix)
meta update, fixed
meta summarize
meta forestplot, esrefline
meta update, random


*** Performing the Meta-regression analysis (reported in the main text)

** RE model
meta update, random
meta regress rct pub_status pub_field pub_region sjr_18
estimates store A
** FE model
meta update, fixed
meta regress rct pub_status pub_field pub_region sjr_18
estimates store B

*** Ploting the effects

coefplot (A, label(Random-effects (N = 35)) pstyle(p1))  ///
         (B, label(Fixed-effects (N = 35))  pstyle(p2))  ///
         , drop(_cons sjr_18) xline(0) msymbol(S)  level (90)


*** Testing for publication bias (Funnel plot) and small-study effects (reported in the main text)
meta update, random 
meta trimfill, funnel
** Imputing the estimates in the righ side of funnel plot (reported in the appendix)
** Getting a updated estimate of the overall effect size
meta trimfill, right


** Contour-enhanced funnel plot (with imputed estimates) (reported in the appendix)
meta trimfill, funnel(contour(1 5 10))

** The Egger regression-based test - formal test for small-study effects (reported in the appendix)
meta bias, egger


*** Estimating the overall effect with a restricted sample (only one estimate from each study) to avoid statisticall dependency between samples
** I selected the most precise one (higher number os cases)

** RE model (reported in the appendix)
meta update, random
meta summarize if _meta_id == 1 | _meta_id == 4  | _meta_id == 8 | _meta_id == 10 | _meta_id == 14 | _meta_id == 17 | _meta_id == 21 | _meta_id == 25 | _meta_id == 29 | _meta_id == 34 
meta forestplot if _meta_id == 1 | _meta_id == 4  | _meta_id == 8 | _meta_id == 10 | _meta_id == 14 | _meta_id == 17 | _meta_id == 21 | _meta_id == 25 | _meta_id == 29 | _meta_id == 34, esrefline

** CE model (reported in the appendix)

meta update, common
meta summarize if _meta_id == 1 | _meta_id == 4  | _meta_id == 8 | _meta_id == 10 | _meta_id == 14 | _meta_id == 17 | _meta_id == 21 | _meta_id == 25 | _meta_id == 29 | _meta_id == 34 
meta forestplot if _meta_id == 1 | _meta_id == 4  | _meta_id == 8 | _meta_id == 10 | _meta_id == 14 | _meta_id == 17 | _meta_id == 21 | _meta_id == 25 | _meta_id == 29 | _meta_id == 34, esrefline


** FE models (reported in the appendix)

meta update, fixed
meta summarize if _meta_id == 1 | _meta_id == 4  | _meta_id == 8 | _meta_id == 10 | _meta_id == 14 | _meta_id == 17 | _meta_id == 21 | _meta_id == 25 | _meta_id == 29 | _meta_id == 34 
meta forestplot if _meta_id == 1 | _meta_id == 4  | _meta_id == 8 | _meta_id == 10 | _meta_id == 14 | _meta_id == 17 | _meta_id == 21 | _meta_id == 25 | _meta_id == 29 | _meta_id == 34, esrefline










































  
